<!--
 * @Author: Wayne 13235388225@163.com
 * @Date: 2023-10-09 16:23:24
 * @LastEditors: Wayne 13235388225@163.com
 * @LastEditTime: 2023-10-09 16:59:57
 * @FilePath: \Jkc-app-front-new\src\views\addressManage\addressManage.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <div class="view-title">用户地址管理</div>
    <el-table
      :data="addressTableData"
      :header-cell-style="{
        borderColor: '#F0F0F0',
        height: '51px',
        background: '#F0F0F0',
        color: '#333',
      }"
      :row-style="{ height: '51px' }"
      :cell-style="{ borderColor: '#F0F0F0' }"
      style="width: 100%; margin-top: 20px"
    >
      <el-table-column prop="name" label="用户姓名" width="180" align="center">
      </el-table-column>
      <el-table-column
        prop="mobile"
        label="用户手机号"
        width="180"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="user_id" label="用户id" align="center">
      </el-table-column>
      <el-table-column prop="address" label="用户地址" align="center">
      </el-table-column>
      <el-table-column prop="created_at" label="创建时间" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button
            @click="handleCheck(scope.row)"
            type="text"
            size="small"
            v-permission="['addressManage:view']"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <div class="page_box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNow"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <!-- 查看弹窗 -->
    <el-dialog title="查看" :visible.sync="dialogVisibleCheck" width="50%">
      <el-table
        :data="addressCheckTableData"
        :header-cell-style="{
          borderColor: '#F0F0F0',
          height: '51px',
          background: '#F0F0F0',
          color: '#333',
        }"
        :row-style="{ height: '51px' }"
        :cell-style="{ borderColor: '#F0F0F0' }"
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column prop="name" label="用户姓名" width="180">
        </el-table-column>
        <el-table-column prop="mobile" label="用户手机号" width="180">
        </el-table-column>
        <el-table-column prop="user_id" label="用户id"> </el-table-column>
        <el-table-column prop="address" label="用户地址"> </el-table-column>
        <el-table-column prop="created_at" label="创建时间"> </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import {
  getAppUserAddressList,
  getAppUserAddressInfo,
} from "@/api/addressManage.js";
export default {
  name: "AddressManage",
  data() {
    return {
      pageNow: 1,
      pageSize: 10,
      total: null,
      addressTableData: [],
      checkId: "",
      addressCheckTableData: [],
      dialogVisibleCheck: false,
    };
  },
  mounted() {
    this.getAppUserAddressList();
  },
  methods: {
    // 获取全部用户收货地址
    getAppUserAddressList() {
      getAppUserAddressList({
        page_now: this.pageNow,
        page_size: this.pageSize,
      }).then((res) => {
        if (res.code == 1) {
          this.addressTableData = res.data;
          this.total = res.page_info.total_count;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 查询一条用户收货地址记录
    getAppUserAddressInfo() {
      getAppUserAddressInfo({
        id: this.checkId,
      }).then((res) => {
        if (res.code == 1) {
          const arr = [];
          arr.push(res.data);
          this.addressCheckTableData = arr;
        } else {
          this.$message.error(res.msg);
          return;
        }
      });
    },

    // 查看
    handleCheck(val) {
      this.checkId = val.id;
      this.getAppUserAddressInfo();
      this.dialogVisibleCheck = true;
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.getAppUserAddressList();
    },
    handleCurrentChange(val) {
      this.pageNow = val;
      this.pageSize = 10;
      this.getAppUserAddressList();
    },
  },
};
</script>
<style lang="scss" scoped></style>
